package com.nwpu.server.admin.service.impl;

import com.nwpu.server.common.response.*;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.nwpu.server.admin.dao.NetworkDao;
import com.nwpu.server.admin.entity.NetworkEntity;
import com.nwpu.server.admin.service.NetworkService;
import org.springframework.util.StringUtils;


/**
 * @author YuXingZh
 */
@Service("networkService")
public class NetworkServiceImpl extends ServiceImpl<NetworkDao, NetworkEntity> implements NetworkService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<NetworkEntity> page = this.page(
                new Query<NetworkEntity>().getPage(params),
                new QueryWrapper<NetworkEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPage1(Map<String, Object> params) {
        // 获取key
        String key = (String) params.get("key");
        QueryWrapper<NetworkEntity> networkEntityQueryWrapper = new QueryWrapper<>();

        if (!StringUtils.isEmpty(key)) {
            networkEntityQueryWrapper.eq("file_type", key);
        }

        IPage<NetworkEntity> page = this.page(
                new Query<NetworkEntity>().getPage(params), networkEntityQueryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void removeNetworkByIds(List<String> asList) {
        //逻辑删除
        baseMapper.deleteBatchIds(asList);
    }

}